Ext.onReady(function(){
    Ext.QuickTips.init();
	Ext.BLANK_IMAGE_URL = 'ext3.2/resources/images/default/s.gif';
   var store = new Ext.data.GroupingStore({
        reader: new Ext.data.JsonReader({fields: Curdisper}),
        data: genData(),
        sortInfo: {field: 'useName', direction: 'ASC'}
    });

    var editor = new Ext.ux.grid.RowEditor({
        saveText: 'Update'
    });
    
    var grid = new Ext.grid.GridPanel({ 
	  plugins: [editor], 
	  columns: [ 
	    { 
	      header   : 'User Name', 
	      dataIndex: 'name', 
	      editor   : new Ext.form.TextField() 
	    }, 
	    { 
	      header   : 'Email', 
	      dataIndex: 'email', 
	      editor   : new Ext.form.TextField() 
	    } 
	  ] 
	 // ... the rest of your grid config here 
	});
    
/** 
 * @event afteredit 
 * Fired after a row is edited and passes validation.  This event is fired 
 * after the store's update event is fired with this edit. 
 * @param {Ext.ux.grid.RowEditor} roweditor This object 
 * @param {Object} changes Object with changes made to the record. 
 * @param {Ext.data.Record} r The Record that was edited. 
 * @param {Number} rowIndex The rowIndex of the row just edited 
 */
'afteredit'
//All you need to do is listen to that event on your RowEditor and save your model object appropriately. First though, we’ll define the Ext.data.Record that we’re using in this grid’s store:

var User = Ext.data.Record.create([ 
  {name: 'user_id', type: 'int'}, 
  {name: 'name',    type: 'string'}, 
  {name: 'email',   type: 'string'} 
]);
//And now the afteredit listener itself

editor.on({ 
  scope: this, 
  afteredit: function(roweditor, changes, record, rowIndex) { 
    //your save logic here - might look something like this: 
    Ext.Ajax.request({ 
      url   : record.phantom ? '/users' : '/users/' + record.get('user_id'), 
      method: record.phantom ? 'POST'   : 'PUT', 
      params: changes, 
      success: function() { 
        //post-processing here - this might include reloading the grid if there are calculated fields 
      } 
    }); 
  } 
});

var grid = new Ext.grid.GridPanel({ 
  //... the same config from above goes here, 
  tbar: [ 
    { 
      text   : "Add User", 
      handler: function() { 
        //make a new empty User and stop any current editing 
        var newUser = new User({}); 
        rowEditor.stopEditing(); 
  
        //add our new record as the first row, select it 
        grid.store.insert(0, newUser); 
        grid.getView().refresh(); 
        grid.getSelectionModel().selectRow(0); 
  
        //start editing our new User 
        rowEditor.startEditing(0); 
      } 
    } 
  ] 
});

   
var editor = new Ext.ux.grid.RowEditor({ 
  saveText  : "My Save Button Text", 
  cancelText: "My Cancel Button Text", 
  clicksToEdit: 1, //this changes from the default double-click activation to single click activation 
  errorSummary: false //disables display of validation messages if the row is invalid 
});

var store = new Ext.data.Store({    
            url: 'getUsers.action',    
                 
            reader: new Ext.data.JsonReader({totalProperty: 'totalProperty',root: 'root'},User),    
            listeners: {    
                'update': function(thiz, record, operation){            //捕捉记录发生更改的事件    
                    var user = thiz.getAt(thiz.indexOf(record)).data;   //获得当前修改后的记录 
                    //原作者这里的代码有些问题，user可以直接这样写 
                    //user = record.data; 
                    if(operation == Ext.data.Record.EDIT){              //判断update时间的操作类型是否为 edit 该事件还有其他操作类型比如 commit,reject    
                        Ext.Ajax.request({    
                            url: 'updateUser.action',                   //修改用户数据 
                            //原作者的params构建这样有些不妥吧，可以直接这样写 
                            //params:user 
                            //没有必要再构建这么一个复杂的json 
                            //这里最好再增加method:'POST',不然多次提交修改数据，肯能会因为缓存失效 
                            params: {                                   //获取修改后的用户数据传到服务器    
                                'user.userid': user.userid,                 
                                'user.password': user.password,    
                                'user.manager': user.manager,    
                                'user.name': user.name,    
                                'user.address': user.address,    
                                'user.zip': user.zip,    
                                'user.company': user.company    
                            },    
                            success: function(response, opts) {    
                                thiz.commitChanges();                   //如果请求成功则更新本地记录:)    
                            },    
                            failure: function(response, opts) {    
                                Ext.Msg.alert('错误','server-side failure with status code ' + response.status);    
                                thiz.rejectChanges();                   //请求失败,回滚本地记录:)    
                            }    
                        });    
                    }    
                },    
                //我认为删除没有必要再sotre里面做 
                'remove': function(thiz,record,index){    
                    Ext.Ajax.request({                                  //捕捉记录删除事件    
                        url: 'deleteUser.action',               
                        params: { 'user.userid': record.data.userid },  //传递被删除记录的id到服务器    
                        failure: function(response, opts) {    
                            Ext.Msg.alert('错误','server-side failure with status code ' + response.status);    
                            store.insert(0,record)                      //如果服务器删除失败,本地插回回来的记录:)    
                        }    
                    });    
                }    
            }    
        });  
  
   



    layout.render(Ext.getBody());

    grid.getSelectionModel().on('selectionchange', function(sm){
        grid.removeBtn.setDisabled(sm.getCount() < 1);
    });
});
